package org.jeecg.common.datasource.enums;


/**
 * @create: 2023-10-11 17:43
 * @description: 数据库类型枚举
 */
public enum DataSourceType {
    MYSQL(1, "mysql", "MYSQL", "com.mysql.cj.jdbc.Driver", "select 1"),
    ORACLE(2,"oracle", "Oracle", "oracle.jdbc.driver.OracleDriver", "select 1 from dual"),
    POSTGRESQL(3,"postgresql", "PostgreSQL", "org.postgresql.Driver", "select 1 "),
    DM(4,"dm", "DM", "dm.jdbc.driver.DmDriver", "select 1 from dual"),
    KINGBASE8(5,"kingbase8", "Kingbase8", "com.kingbase8.Driver", "select 1 "),
    OCEANBASE(6,"oceanbase", "Oceanbase", "com.oceanbase.jdbc.Driver", "select 1 from dual"),
    TDSQL(7,"tdsql", "TDSQL", "com.mysql.cj.jdbc.Driver", "select 1 ");

    private Integer id;
    private String type;
    private String name;
    private String driver;
    private String test;

    DataSourceType(Integer id, String type, String name, String driver, String test) {
        this.id = id;
        this.type = type;
        this.name = name;
        this.driver = driver;
        this.test = test;
    }

    public String getType() {
        return type;
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getDriver() {
        return driver;
    }

    public String getTest() {
        return test;
    }

    public static DataSourceType get(Integer id) {
        for (DataSourceType dsType : values()) {
            if (dsType.getId().equals(id)) {
                return dsType;
            }
        }
        return null;
    }

    public static DataSourceType getByType(String type) {
        for (DataSourceType dsType : values()) {
            if (dsType.getType().equals(type)) {
                return dsType;
            }
        }
        return null;
    }

    public static DataSourceType getByDriver(String driver) {
        for (DataSourceType dsType : values()) {
            if (dsType.getDriver().equals(driver)) {
                return dsType;
            }
        }
        return null;
    }
}
